#!/usr/bin/env bash
RUN_NAME="rpc-server"
ENV=
SERVER_DIR=/data/rpc-server/${RUN_NAME}

function build() {
  go env -w GOPRIVATE=gitee.com/cyberocx
  git config --global url."git@github.com:cyberocx".insteadOf https://gitee.com/cyberocx
  mkdir -p output/bin
  mkdir -p output/conf

  cp conf/$ENV.yaml output/conf/${RUN_NAME}.yaml

  GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" -trimpath -o output/bin/${RUN_NAME}
}

if [ "$1" == '' ]; then
  ENV="local"
else
  if [[ "$1" != 'local' ]] && [[ "$1" != 'test' ]]  && [[ "$1" != 'new-test' ]] && [[ "$1" != 'pre' ]] && [[ "$1" != 'product' ]] ; then
    echo "usage: ./build.sh [local|test|new-test|pre|product]"
    exit 1
  fi
  ENV="$1"
fi

echo "运行环境：$ENV"

build
